﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Register.Model;
using Register.DAL;
using Register.Command;
using Register.BLL;
using System.Web.Script.Serialization;
namespace RegisterWeb.Manager.SystemManager.ashx
{
    /// <summary>
    /// SystemLoggerHandler 的摘要说明
    /// </summary>
    public class SystemLoggerHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action=context.Request["action"];
            #region 查询系统日志
            if (action.Equals("get")) {


                int row = int.Parse(context.Request["rows"].ToString());
                int page = int.Parse(context.Request["page"].ToString());
                List<LogerInfo> list = new List<LogerInfo>();
                list = SystemManageBLL.GetPagedLogerInfo(row, page,"  1=1");  //临时模拟医生

                List<LogerInfoJSON> json = new List<LogerInfoJSON>();
                foreach (LogerInfo log in list)
                {


                    json.Add(new LogerInfoJSON(Convert.ToString(log.Logger_ID),Convert.ToString(log.Logger_Info),log.Logger_Level,log.Logger_Name,Convert.ToString(log.Logger_State),log.Logger_Thread,Convert.ToString(log.Logger_Time)));
                }

                LogerInfoListJSON logerInfoListJSON = new LogerInfoListJSON();
                logerInfoListJSON.total = OutpatientBLL.GetOutpatientInfoCount(null);
                logerInfoListJSON.rows = json;

                JavaScriptSerializer jss = new JavaScriptSerializer();
                context.Response.Write(jss.Serialize(logerInfoListJSON));
            }
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
class LogerInfoListJSON
{

    public int total { get; set; }
    public List<LogerInfoJSON> rows { get; set; }

}
class LogerInfoJSON
{

    public string Logger_ID
    {
        set;
        get;
    }
    public string Logger_Name
    {
        get;
        set;
    }
    public string Logger_Level
    {
        get;
        set;
    }

    public string Logger_Thread
    {
        get;
        set;
    }
    public string Logger_Time
    {
        get;
        set;
    }
    public string Logger_Info
    {
        get;
        set;
    }

    public string Logger_State
    {
        get;
        set;
    }

    public LogerInfoJSON(string Logger_ID,string Logger_Info,string Logger_Level,string Logger_Name,string Logger_State,string Logger_Thread,string Logger_Time)
    {
        this.Logger_ID = Logger_ID;
        this.Logger_Info = Logger_Info;
        this.Logger_Level = Logger_Level;
        this.Logger_Name = Logger_Name;
        this.Logger_State = Logger_State;
        this.Logger_Thread = Logger_Thread;
        this.Logger_Time = Logger_Time;
        
    }
}